import java.util.Scanner;

class timer {
    private long startTime=-1;
    private long stopTime=-1;
    private int runningState=0; //1启动 3暂停 4分段
    private double sumTime=0;

    public boolean split() {
        if(this.runningState!=0) {
            return false;
        }
        this.runningState=4;
        this.reset();
        return true;
    }

    public double getSplitTime() {
        if(this.runningState!=4) {
            return 0;
        }
        return (System.currentTimeMillis()-this.startTime)*0.001;
    }

    public double getTime() {
        return (this.stopTime-this.startTime)*0.001+this.sumTime;
    }

    private void reset() {
        this.sumTime=0;
        this.startTime=System.currentTimeMillis();
    }

    public boolean start() {
        if(this.runningState!=0){
            return false;
        }
        this.runningState=1;
        this.reset();
        return true;
    }

    public double stop() {
        if(this.runningState!=3)
            this.stopTime=System.currentTimeMillis();
        this.runningState=0;
        return this.getTime();
    }

    public boolean suspend(){
        if(this.runningState!=1) {
            return false;
        }
        this.runningState=3;
        this.stopTime=System.currentTimeMillis();
        this.sumTime+=(this.stopTime-this.startTime)*0.001;
        return true;
    }

    public boolean resume(){
        if(this.runningState!=3){
            return false;
        }
        this.runningState=1;
        this.startTime=System.currentTimeMillis();
        return true;
    }
}

class timerTest {
    public static void main(String[] args) {
        System.out.println("输入操作1开始2暂停3恢复4停止5分段计时6getSplitTime");
        Scanner scan = new Scanner(System.in);
        timer atimer = new timer();

        while(true) {
            switch(scan.nextInt()){
                case 1:
                    if (!atimer.start())
                        System.out.println("无效操作");
                    break;
                case 2:
                    if (!atimer.suspend())
                        System.out.println("无效操作");
                    break;
                case 3:
                    if (!atimer.resume())
                        System.out.println("无效操作");
                    break;
                case 4:
                {
                    double result=atimer.stop();
                    if (result==0)
                        System.out.println("无效操作");
                    else
                        System.out.println(result);
                    break;
                }
                case 5:
                    if(!atimer.split())
                        System.out.println("无效操作");
                    break;
                case 6:
                {
                    double result=atimer.getSplitTime();
                    if(result==0){
                        System.out.println("无效操作");
                    }
                    else {
                        System.out.println(result);
                    }
                    break;
                }
                default:
                    System.out.println("错误的输入");
            }
        }
    }
}
